#!/bin/sh

export HOST_PORT=4920;

echo "**** Running QEMU SSH on port ${HOST_PORT} ****";

export SMP=2;
export QEMU=/usr/bin/qemu-system-x86_64;
export KERNEL=/root/documents/build/linux.build/arch/x86_64/boot/bzImage;
export ROOTFS=/root/documents/disk.ext2;


while [ "$1" != "" ]; do
    if [ "$1" = "-debug" ];
    then
        echo "**** GDB port $((HOST_PORT + 1)) ****";
        DEBUG="-gdb tcp::$((HOST_PORT + 1)) -S -d in_asm -D debug.log";
    fi;
    if [ "$1" = "-smp" ];
    then
        SMP="$2";
        shift;
    fi;
    shift;
done;

$QEMU \
 $DEBUG \
 -m 4G \
 -nographic \
 -kernel $KERNEL \
 -append "nokaslr console=ttyS0 ro root=/dev/sda"   \
 -drive file=$ROOTFS,format=raw \
 -netdev user,id=net0,net=192.168.100.1/24,dhcpstart=192.168.100.128,hostfwd=tcp::${HOST_PORT}-:22 \
 -device e1000,netdev=net0 \
 -smp $SMP 
